package org.sj.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bao.bean.PhoneInfo;
import org.bao.service.impl.PhoneServiceImpl;
import org.bao.utils.MyUtils;

import com.alibaba.fastjson.JSON;

/**
 * Servlet implementation class ProductPrice
 */
@WebServlet("/ProductPrice")
public class ProductPrice extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//接收发送的数据
		String strphoneid = request.getParameter("phoneid");
		//创建一个实例对象
		PhoneInfo phoneS =  MyUtils.getInstance(PhoneInfo.class);
		//将phoneid放入对象中
		phoneS.setPhoneid(strphoneid);
		//连接数据库
		List<PhoneInfo> lstPhones = MyUtils.getInstance(PhoneServiceImpl.class).queryPhoneInfo(phoneS);
		System.out.println("查询结果：" + lstPhones);
		//转换为json
		String strJson = JSON.toJSONString(lstPhones);
		System.out.println("json:"+strJson);
		//发送数据
		PrintWriter pw = response.getWriter();
		pw.write(strJson);
		pw.flush();
	}

}
